import 'package:flutter/material.dart';
import 'package:untitled/pages/login_widget/SignUp/background.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:untitled/pages/login_widget/commponents/already_have_an_account_acheck.dart';
import 'package:untitled/pages/login_widget/commponents/input_field.dart';
import 'package:untitled/pages/login_widget/commponents/rounded_button.dart';
import 'package:untitled/pages/login_widget/commponents/rounded_password_field.dart';
import 'package:untitled/pages/login_widget/commponents/social_icon.dart';
import 'package:untitled/utils/Check.dart';

class SignupBody extends StatefulWidget {
  const SignupBody({Key? key}) : super(key: key);

  @override
  State<SignupBody> createState() => _SignupBodyState();
}

class _SignupBodyState extends State<SignupBody> {
  String email="";
  String username="";
  String password="";
  TextEditingController makeSureControl=new TextEditingController();
  String token="";
  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return BackgroundSing(
      child: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("SIGNUP",style: TextStyle(fontWeight:FontWeight.bold,)),
            SizedBox(height:size.height *0.03),
            SvgPicture.asset(
              "assets/icons/signup.svg",
              height: size.height * 0.35,
            ),
            RoundedInputField(
              hintText: "Sign Email",
              icon:Icons.alternate_email,
              onChanged: (value){
                email = value;
              },
            ),
            RoundedInputField(
              hintText: "Username",
              icon: Icons.emoji_people,
              onChanged: (value) {
                username=value;
            },
          ),
          RoundedPasswordField(
            onChanged: (value) {
              password = value;
            },
            myHintText: "Password",
          ),
          RoundedPasswordField(
            myController: makeSureControl,
            myHintText: "Password",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Padding(padding: EdgeInsets.only(left:35.0)),
              Expanded(
                child: RoundedInputField(
                  hintText: "Token",
                  icon: Icons.code,
                  onChanged: (value){
                    token=value;
                  },
                )
              ),
              Expanded(
                child: RoundedButton(
                  text: "Send", 
                  press: (){
                    // 校验
                    if(!isEmail(email)){
                      Fluttertoast.showToast(
                        msg: '请保证邮箱正确!',
                        gravity: ToastGravity.CENTER,
                        textColor: Colors.grey
                      );
                    
                    }else if(!isUsername(username)){
                       Fluttertoast.showToast(
                        msg: 'username 5~10位 英文字母开头 只包含英文字母 数字 _ 至少有一个大写英文字母',
                        gravity: ToastGravity.CENTER,
                        textColor: Colors.grey
                      );

                    }else if(!isPassword(password)){
                        Fluttertoast.showToast(
                            msg: "password 6~12位 只包含英文字母 数字 _ ",
                            gravity: ToastGravity.CENTER,
                            textColor: Colors.grey);
                    }else if(!(makeSureControl.text==password)){
                        makeSureControl.clear();
                        Fluttertoast.showToast(
                            msg: "请确认第二次输入与第一次相同",
                            gravity: ToastGravity.CENTER,
                            textColor: Colors.grey);
                    }else{
                        print("try to send");
                        //send();
                      }
                  }
                )
              ),
              Padding(padding: EdgeInsets.only(left: 40.0)),
            ],
          ),
          RoundedButton(text: "SIGNUP", press: (){
            //注册
            //SignUp(context);
          }),
          SizedBox(height:size.height * 0.03),
          AlreadyHaveAnAccountCheck(login: false, press: (){

          }),
          SizedBox(height: 20,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SocalIcon(
                iconSrc: "assets/icons/facebook.svg",
                press: (){},
              ),
               SocalIcon(
                  iconSrc: "assets/icons/twitter.svg",
                  press: () {},
                ),
                SocalIcon(
                  iconSrc: "assets/icons/google-plus.svg",
                  press: () {},
                ),
            ],
          )

          ],
        ),
      

      )
    );
    
  }
}